import instance from '../../utils/request.js'

// 获取新闻
export const getNewsAPI = (params) => {
  const { newsId } = params
  return instance({
    url: `/api/news/${newsId}`,
    method: 'GET',
  })
}

// 获取新闻列表
export const getNewsListAPI = (params) => {
  const { keyword, authId, pub_date, pageSize=10, pageNum=1 } = params
  return instance({
    url: `/api/news`,
    method: 'GET',
    params: { keyword, authId, pub_date, pageSize, pageNum }  
  })
}

// 发布新闻
export const publishNewsAPI = (data) => {
  const { coverImgUrl, publisher, title, content, authId } = data
  return instance({
    url: `/api/news`,
    method: 'POST',
    data: { coverImgUrl, publisher, title, content, authId }
  })
}

// 删除新闻
export const deleteNewsAPI = (params) => {
  const { newsId, authId } = params
  return instance({
    url: `/api/news/${newsId}`,
    method: 'DELETE',
    params: { authId }
  })
}
